package cn.smile.dao;

import cn.smile.pojo.Permission;
import cn.smile.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: MaoSuyu
 * @User：John
 * @Date: 2019/7/4
 * @Time: 17:42
 * @Description: No Description
 */
@Repository
public interface PermissionDaoMapper {

    /**
     * 插入权限到权限表
     *
     * @param permission
     * @return
     */
    @Insert("INSERT INTO permission ( permission, permissionName ) VALUES( #{permission}, #{permissionName} )")
    int insert(Permission permission);

    /**
     * 查询所有权限，刷新权限时方便对比重复的地方
     *
     * @return
     */
    @Select("SELECT permission FROM permission")
    List<String> selectPermission();

    /**
     * 根据id去查询用户拥有什么权限
     * @param user
     * @return
     */
    @Select("SELECT permission FROM role_permission rp INNER JOIN permission p ON rp.permissionId=p.id WHERE (SELECT roleId FROM user_role WHERE userId=#{id})")
    List<String> selectPermissionById(User user);

}
